      SUBROUTINE XERROR(MESSG,NMESSG,NERR,LEVEL)                        XER   10
C
C     ABSTRACT
C        XERROR PROCESSES A DIAGNOSTIC MESSAGE, IN A MANNER
C        DETERMINED BY THE VALUE OF LEVEL AND THE CURRENT VALUE
C        OF THE LIBRARY ERROR CONTROL FLAG, KONTRL.
C        (SEE SUBROUTINE XSETF FOR DETAILS.)
C
C     DESCRIPTION OF PARAMETERS
C      --INPUT--
C        MESSG - THE HOLLERITH MESSAGE TO BE PROCESSED, CONTAINING
C                NO MORE THAN 72 CHARACTERS.
C        NMESSG- THE ACTUAL NUMBER OF CHARACTERS IN MESSG.
C        NERR  - THE ERROR NUMBER ASSOCIATED WITH THIS MESSAGE.
C                NERR MUST NOT BE ZERO.
C        LEVEL - ERROR CATEGORY.
C                =2 MEANS THIS IS AN UNCONDITIONALLY FATAL ERROR.
C                =1 MEANS THIS IS A RECOVERABLE ERROR.  (I.E., IT IS
C                   NON-FATAL IF XSETF HAS BEEN APPROPRIATELY CALLED.)
C                =0 MEANS THIS IS A WARNING MESSAGE ONLY.
C                =-1 MEANS THIS IS A WARNING MESSAGE WHICH IS TO BE
C                   PRINTED AT MOST ONCE, REGARDLESS OF HOW MANY
C                   TIMES THIS CALL IS EXECUTED.
C
C     EXAMPLES
C        CALL XERROR(23HSMOOTH -- NUM WAS ZERO.,23,1,2)
C        CALL XERROR(43HINTEG  -- LESS THAN FULL ACCURACY ACHIEVED.,
C                    43,2,1)
C        CALL XERROR(65HROOTER -- ACTUAL ZERO OF F FOUND BEFORE INTERVAL
C    1 FULLY COLLAPSED.,65,3,0)
C        CALL XERROR(39HEXP    -- UNDERFLOWS BEING SET TO ZERO.,39,1,-1)
C
C     WRITTEN BY RON JONES, WITH SLATEC COMMON MATH LIBRARY SUBCOMMITTEE
C END OF ABSTRACT
C     REVISED BY K HASKELL TO CHECK INPUT ARGS, 2/18/80
C
      DIMENSION MESSG(NMESSG)
C     CHECK FOR VALID INPUT
      LKNTRL = J4SAVE (2,0,.FALSE.)
      IF (NMESSG.GT.0) GO TO 10
      IF (LKNTRL.GT.0) CALL XERPRT(17HFATAL ERROR IN...,17)
      CALL XERPRT (33HXERROR -- NMESSG MUST BE POSITIVE,33)
      IF (LKNTRL.GT.0) CALL FDUMP
      IF (LKNTRL.GT.0) CALL XERPRT(29HJOB ABORT DUE TO FATAL ERROR.,
     1 29)
      IF (LKNTRL.GT.0) CALL XERSAV (1H ,0,0,0,KDUMMY)
      CALL XERABT (23HXERROR -- INVALID INPUT,23)
      RETURN
   10 CONTINUE
      IF (NERR.NE.0) GO TO 15
      IF (LKNTRL.GT.0) CALL XERPRT(17HFATAL ERROR IN...,17)
      CALL XERPRT (28HXERROR -- NERR=0 IS AN ERROR,28)
      IF (LKNTRL.GT.0) CALL FDUMP
      IF (LKNTRL.GT.0) CALL XERPRT(29HJOB ABORT DUE TO FATAL ERROR.,
     1 29)
      IF (LKNTRL.GT.0) CALL XERSAV (1H ,0,0,0,KDUMMY)
      CALL XERABT (23HXERROR -- INVALID INPUT,23)
      RETURN
   15 CONTINUE
      IF ((LEVEL.GE.(-1)).AND.(LEVEL.LE.2)) GO TO 20
      IF (LKNTRL.GT.0) CALL XERPRT(17HFATAL ERROR IN...,17)
      CALL XERPRT (32HXERROR -- INVALID VALUE OF LEVEL,32)
      IF (LKNTRL.GT.0) CALL FDUMP
      IF (LKNTRL.GT.0) CALL XERPRT(29HJOB ABORT DUE TO FATAL ERROR.,
     1 29)
      IF (LKNTRL.GT.0) CALL XERSAV (1H ,0,0,0,KDUMMY)
      CALL XERABT (23HXERROR -- INVALID INPUT,23)
      RETURN
   20 CONTINUE
      CALL XERRWV(MESSG,NMESSG,NERR,LEVEL,0,0,0,0,0.,0.)
      RETURN
      END
